#include "netconn.h"
#include <memory.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#include <stdio.h>

int decode_msg(char *data,int data_len,void **msg);

int conn_connected(int fd,struct sockaddr *addr){
	struct sockaddr_in *inaddr=(struct sockaddr_in *)addr;
	printf("Client connected: %s %d\n",inet_ntoa(inaddr->sin_addr),ntohs(inaddr->sin_port));
	return 0;
}

int main(int c,char **v){

	struct sockaddr_in server;
    	memset((struct sockaddr*)&server,0,sizeof(server));
    	server.sin_family=AF_INET;
    	server.sin_addr.s_addr=htonl(INADDR_ANY);
    	server.sin_port=htons(7890);

	struct netevent_handlers event_hdl;
	event_hdl.connected=conn_connected;

	struct msgPackage_handlers msg_hdl;
	msg_hdl.decoder=decode_msg;

	start_netListen((struct sockaddr *)&server,&event_hdl,&msg_hdl);
	return 0;
}

int decode_msg(char *data,int data_len,void **msg){
	data[data_len]='\0';
	printf("I can print %d bytes,the msg from client is %s \n",data_len,data);
	return data_len;
}
